home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / partitio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.4 KB  |  113 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  partition.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. #ifndef PARTiTIONH
  18. #define PARTITIONH
  19.  
  20. //------------------------------------------------------------------------------
  21. // partition   (union find)
  22. //
  23. // Stefan Naeher  (1989)
  24. //------------------------------------------------------------------------------
  25.  
  26. #include <LEDA/basic.h>
  27.  
  28.  
  29. class partition_node {
  30.  
  31. friend class partition;
  32.  
  33. partition_node* father;
  34. partition_node* next;
  35. int size;
  36. ent info;
  37.  
  38. public:
  39.  
  40. partition_node(ent x, partition_node* n)  
  41.   father=0; size=1; info=x; next = n; 
  42.  }
  43.  
  44. OPERATOR_NEW(4)
  45. OPERATOR_DEL(4)
  46.  
  47. };
  48.  
  49.  
  50. // a partition item is a pointer to a partition node:
  51.  
  52. typedef partition_node* partition_item;
  53.  
  54.  
  55.  
  56. class partition {
  57.  
  58. virtual void clear_inf(ent&) const {}
  59.  
  60. partition_item used_items;                 // List of used partition items
  61.  
  62. public:  // operations 
  63.  
  64. void  union_blocks(partition_item,partition_item);
  65. partition_item find(partition_item);
  66.  
  67. partition_item make_block(ent x = nil) 
  68. { used_items = new partition_node(x,used_items); 
  69.   return used_items; 
  70.  }
  71.  
  72. int  same_block(partition_item a, partition_item b) 
  73. { return find(a)==find(b); }
  74.  
  75. ent   inf(partition_item a) { return find(a)->info; }
  76.  
  77. void  set_inf(partition_item a, ent x) { find(a)->info = x; }
  78.  
  79. void clear();                      // deletes all used items
  80.  
  81.  partition() { used_items = 0; }   // constructor
  82. ~partition() { clear();  }         // destructor 
  83.  
  84. };
  85.  
  86.  
  87. //------------------------------------------------------------------------------
  88. // PARTITION  (named partitions)
  89. //-----------------------------------------------------------------------------
  90.  
  91. #define PARTITION(type) name2(type,PARTITION)
  92.  
  93. #define PARTITIONdeclare(type)\
  94. \
  95. struct PARTITION(type) : public partition {\
  96. \
  97. void clear_inf(ent& x) const { Clear(*(type*)&x); }\
  98. \
  99. partition_item make_block(type x) { return partition::make_block(Ent(x)); }\
  100. \
  101. type  inf(partition_item a) { return (type)partition::inf(a); }\
  102. \
  103. void  set_inf(partition_item a, type x) { partition::set_inf(a,Ent(x)); }\
  104. \
  105.  PARTITION(type)() {}\
  106. ~PARTITION(type)() {}\
  107. };
  108.  
  109.  
  110. #endif
  111.